<template>
  <div>
    <!-- 搜索栏 -->
    <van-search v-model="keyword" placeholder="请输入搜索关键词" />
    <!-- 轮播图 -->
    <van-swipe :autoplay="3000">
      <van-swipe-item v-for="(item, index) in images" :key="index">
        <van-image :src="item.picUrl" height="300" />
      </van-swipe-item>
    </van-swipe>
    <!-- 标签 -->
    
    <!-- 标签 -->
    <!-- 商品列表 -->
    <goodsList
      :goodsList="goodsList"
      @addCart="addCart"
      @del="
        (index) => {
          this.goodsList.splice(index, 1);
        }
      "
    />
    <!-- 商品列表 -->
  </div>
</template>
<script>
import goodsList from "./indexList";
export default {
  components: {
    goodsList,
  },
  data() {
    return {
      keyword: "",
      images: [],
      goodsList: [],
    
    };
  },
  created() {
    this.image();
    this.getList();
  },
  methods: {
    //获取轮播图的数据列表
    image() {
      this.$axios.get("https://api.it120.cc/small4/banner/list").then((res) => {
        console.log(res.data);
        this.images = res.data;
      });
    },
    //获取商品的数据列表接口
    getList() {
      this.$axios.get("/json/list.json").then((res) => {
        console.log(res.result);
        this.goodsList = res.result;
      });
    },
    //加入购物车的方法
    addCart(goods) {
      console.log("购物车的数据", goods);
      this.$set(goods, "checked", false);
      this.$set(goods, "num", 1);
      this.$store.commit("addCart1", goods);
      this.$toast.success("加入购物车成功");
    },
    
   
  },
 
};
</script>